<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::CoreExtensions::Date::Conversions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::CoreExtensions::Date::Conversions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activesupport/lib/active_support/core_ext/date/conversions_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Converting dates to formatted strings, times, and datetimes.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000575">readable_inspect</a>&nbsp;&nbsp;
      <a href="#M000576">to_date</a>&nbsp;&nbsp;
      <a href="#M000578">to_datetime</a>&nbsp;&nbsp;
      <a href="#M000574">to_formatted_s</a>&nbsp;&nbsp;
      <a href="#M000577">to_time</a>&nbsp;&nbsp;
      <a href="#M000579">xmlschema</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DATE_FORMATS</td>
          <td>=</td>
          <td class="context-item-value">{           :short        =&gt; &quot;%e %b&quot;,           :long         =&gt; &quot;%B %e, %Y&quot;,           :db           =&gt; &quot;%Y-%m-%d&quot;,           :number       =&gt; &quot;%Y%m%d&quot;,           :long_ordinal =&gt; lambda { |date| date.strftime(&quot;%B #{date.day.ordinalize}, %Y&quot;) }, # =&gt; &quot;April 25th, 2007&quot;           :rfc822       =&gt; &quot;%e %b %Y&quot;</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000575" class="method-detail">
        <a name="M000575"></a>

        <div class="method-heading">
          <a href="#M000575" class="method-signature">
          <span class="method-name">readable_inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overrides the default inspect method with a human readable one, e.g.,
&quot;Mon, 21 Feb 2005&quot;
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000575-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000575-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 66</span>
66:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">readable_inspect</span>
67:           <span class="ruby-identifier">strftime</span>(<span class="ruby-value str">&quot;%a, %d %b %Y&quot;</span>)
68:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000576" class="method-detail">
        <a name="M000576"></a>

        <div class="method-heading">
          <a href="#M000576" class="method-signature">
          <span class="method-name">to_date</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to keep Time, Date and DateTime instances interchangeable on
conversions. In this case, it simply returns <tt>self</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000576-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000576-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 72</span>
72:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_date</span>
73:           <span class="ruby-keyword kw">self</span>
74:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000578" class="method-detail">
        <a name="M000578"></a>

        <div class="method-heading">
          <a href="#M000578" class="method-signature">
          <span class="method-name">to_datetime</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Converts a Date instance to a DateTime, where the time is set to the
beginning of the day and UTC offset is set to 0.
</p>
<h4>Example:</h4>
<pre>
  date = Date.new(2007, 11, 10)  # =&gt; Sat, 10 Nov 2007

  date.to_datetime               # =&gt; Sat, 10 Nov 2007 00:00:00 0000
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000578-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000578-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 97</span>
97:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_datetime</span>
98:           <span class="ruby-operator">::</span><span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">civil</span>(<span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>)
99:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000574" class="method-detail">
        <a name="M000574"></a>

        <div class="method-heading">
          <a href="#M000574" class="method-signature">
          <span class="method-name">to_formatted_s</span><span class="method-args">(format = :default)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert to a formatted string. See DATE_FORMATS for predefined formats.
</p>
<p>
This method is aliased to <tt>to_s</tt>.
</p>
<h4>Examples:</h4>
<pre>
  date = Date.new(2007, 11, 10)       # =&gt; Sat, 10 Nov 2007

  date.to_formatted_s(:db)            # =&gt; &quot;2007-11-10&quot;
  date.to_s(:db)                      # =&gt; &quot;2007-11-10&quot;

  date.to_formatted_s(:short)         # =&gt; &quot;10 Nov&quot;
  date.to_formatted_s(:long)          # =&gt; &quot;November 10, 2007&quot;
  date.to_formatted_s(:long_ordinal)  # =&gt; &quot;November 10th, 2007&quot;
  date.to_formatted_s(:rfc822)        # =&gt; &quot;10 Nov 2007&quot;
</pre>
<h2>Adding your own time formats to <a href="Conversions.html#M000574">to_formatted_s</a></h2>
<p>
You can add your own formats to the Date::DATE_FORMATS hash. Use the format
name as the hash key and either a strftime string or Proc instance that
takes a date argument as the value.
</p>
<pre>
  # config/initializers/time_formats.rb
  Date::DATE_FORMATS[:month_and_year] = &quot;%B %Y&quot;
  Date::DATE_FORMATS[:short_ordinal] = lambda { |date| date.strftime(&quot;%B #{date.day.ordinalize}&quot;) }
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000574-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000574-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 53</span>
53:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_formatted_s</span>(<span class="ruby-identifier">format</span> = <span class="ruby-identifier">:default</span>)
54:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">formatter</span> = <span class="ruby-constant">DATE_FORMATS</span>[<span class="ruby-identifier">format</span>]
55:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">formatter</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:call</span>)
56:               <span class="ruby-identifier">formatter</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>).<span class="ruby-identifier">to_s</span>
57:             <span class="ruby-keyword kw">else</span>
58:               <span class="ruby-identifier">strftime</span>(<span class="ruby-identifier">formatter</span>)
59:             <span class="ruby-keyword kw">end</span>
60:           <span class="ruby-keyword kw">else</span>
61:             <span class="ruby-identifier">to_default_s</span>
62:           <span class="ruby-keyword kw">end</span>
63:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000577" class="method-detail">
        <a name="M000577"></a>

        <div class="method-heading">
          <a href="#M000577" class="method-signature">
          <span class="method-name">to_time</span><span class="method-args">(form = :local)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Converts a Date instance to a Time, where the time is set to the beginning
of the day. The timezone can be either :local or :utc (default :local).
</p>
<h4>Examples:</h4>
<pre>
  date = Date.new(2007, 11, 10)  # =&gt; Sat, 10 Nov 2007

  date.to_time                   # =&gt; Sat Nov 10 00:00:00 0800 2007
  date.to_time(:local)           # =&gt; Sat Nov 10 00:00:00 0800 2007

  date.to_time(:utc)             # =&gt; Sat Nov 10 00:00:00 UTC 2007
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000577-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000577-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 86</span>
86:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_time</span>(<span class="ruby-identifier">form</span> = <span class="ruby-identifier">:local</span>)
87:           <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{form}_time&quot;</span>, <span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>)
88:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000579" class="method-detail">
        <a name="M000579"></a>

        <div class="method-heading">
          <a href="#M000579" class="method-signature">
          <span class="method-name">xmlschema</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000579-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000579-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb, line 101</span>
101:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xmlschema</span>
102:           <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">xmlschema</span>
103:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>